<?php

include_once('../../base/Constants.php');
include_once('../../base/DBHelper.php');
include_once('../../base/SQLBuilder.php');
include_once('../../base/Response.php');
header("content-type:text/html;charset=utf8");

$response = new Response();
$userName = isset($_GET['username']) ? $_GET['username'] : "";
$password = isset($_GET['password']) ? $_GET['password'] : "";
if ($userName == '' || $password == '') {
	$response->msg = "用户名和密码不能为空";
	die($response->toJson());
}

$dbHelper = new DBHelper();
$sqlBuilder = new SQLBuilder();
$sqlStr = $sqlBuilder->insert(TABLE_ADMIN)
	->addValue("name", $userName)
	->addValue("password", $password)
	->build();

try {
	$dbHelper->connectDB();
	$dbHelper->exeSQL($sqlStr);
	$response->code = RESPONSE_OK;
	$response->msg = "注册成功";
} catch (Exception $e) {
	$response->msg = $e->getMessage();
}
echo $response->toJson();
$dbHelper->disconnectDB();

?>